package com.family.web.controller.pedigree;


import com.family.common.annotation.Log;
import com.family.common.core.controller.BaseController;
import com.family.common.core.domain.AjaxResult;
import com.family.common.core.page.TableDataInfo;
import com.family.common.enums.BusinessType;
import com.family.pedigree.domain.FamilyArticle;
import com.family.pedigree.service.IFamilyArticleService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 文章信息 前端控制器
 * </p>
 *
 * @author forever
 * @since 2024-11-17
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/family/article")
public class FamilyArticleController extends BaseController {

    private final IFamilyArticleService familyArticleService;


    /**
     * 获取文章通知
     *
     * @return 返回文章通知
     */
    @GetMapping("/notice")
    public AjaxResult notice() {
        return AjaxResult.success(familyArticleService.getNotice());
    }

    /**
     * 查询前五重大文件
     * 1.根据文章等级排序
     * 2.根据发布时间排序
     *
     * @return 返回前五条文章数据
     */
    @GetMapping("/top")
    public AjaxResult articleTopFive() {
        return AjaxResult.success(familyArticleService.getTopFive());
    }

    /**
     * 添加文章
     */
    @Log(title = "添加文章", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FamilyArticle article) {

        familyArticleService.add(article);
        return success();
    }

    /**
     * 分页
     */
    @GetMapping("/list")
    public TableDataInfo getList(FamilyArticle article) {
        startPage();
        return getDataTable(familyArticleService.getList(article));
    }

    @GetMapping("/draft/list")
    public TableDataInfo getDraftList(FamilyArticle article) {
        startPage();
        return getDataTable(familyArticleService.getDraftList(article));
    }

    @GetMapping("/down/list")
    public TableDataInfo getDownList(FamilyArticle article) {
        startPage();
        return getDataTable(familyArticleService.getDownList(article));
    }

    /**
     * 编辑
     */
    @Log(title = "编辑文章", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FamilyArticle article) {
        familyArticleService.edit(article);
        return success();
    }

    /**
     * 上下架
     */
    @Log(title = "上下架文章", businessType = BusinessType.UPDATE)
    @PutMapping("/upOrDown")
    public AjaxResult upOrDown(@RequestBody FamilyArticle article) {
        familyArticleService.upOrDown(article);
        return success();
    }

    /**
     * 归档
     */
    @Log(title = "归档文章", businessType = BusinessType.UPDATE)
    @DeleteMapping("/{articleId}")
    public AjaxResult articleCase(@PathVariable Long articleId) {
        familyArticleService.articleCase(articleId);
        return success();
    }
}
